home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / ferm < prev    next >
Encoding:
Text File  |  2010-02-15  |  3.4 KB  |  130 lines

  1. #!/bin/sh
  2. #
  3. # ferm          Configure ferm firewall rules from /etc/ferm.conf
  4. #
  5. #               Written by Max Kellermann <max@duempel.org>
  6. #
  7. # Version:      $Revision: 315 $
  8. ### BEGIN INIT INFO
  9. # Provides:          ferm
  10. # Required-Start:    $network $remote_fs
  11. # Required-Stop:     $network $remote_fs
  12. # Default-Start:     S
  13. # Default-Stop:         0 6 
  14. # Description: Starts ferm firewall configuration 
  15. # short-description: ferm firewall configuration
  16. ### END INIT INFO
  17.  
  18. #includes lsb functions 
  19. . /lib/lsb/init-functions
  20.  
  21.  
  22. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  23. FERM=/usr/sbin/ferm
  24. CONFIG=/etc/ferm/ferm.conf
  25. NAME=ferm
  26. DESC="Firewall"
  27. CACHE_DIR=/var/cache/ferm
  28.  
  29. test -x $FERM || exit 0
  30.  
  31. umask 0077
  32.  
  33. unset ENABLED
  34. FAST=yes
  35. CACHE=no
  36. OPTIONS=
  37. unset DOMAINS
  38. [ -r /etc/default/ferm ] && . /etc/default/ferm
  39.  
  40. test -f "$CONFIG" || exit 0
  41.  
  42. if [ -n "$DOMAINS" ]; then
  43.     echo "Warning: the DOMAINS setting in /etc/default/ferm is deprecated." >&2
  44. fi
  45.  
  46. if [ "$ENABLED" != "yes"  ]; then
  47.     if [ "$VERBOSE" != no ]; then
  48.         if [ -z "$ENABLED" ]; then
  49.             echo "Not starting ferm - run 'dpkg-reconfigure ferm' to enable it"
  50.         else
  51.             echo "Not starting ferm - edit /etc/default/ferm to enable it"
  52.         fi
  53.     fi
  54.     exit 0
  55. fi
  56.  
  57. [ "$CACHE" = "yes" -a ! -d $CACHE_DIR ] && CACHE=no
  58.  
  59. set -e
  60.  
  61. configure_ferm() {
  62.     local CACHE_NAME=${1:-start}
  63.  
  64.     if [ "$CACHE" = "yes" ]; then
  65.         local CACHE_FILE=$CACHE_DIR/$CACHE_NAME.sh
  66.  
  67.         # The .kernel file saves the kernel version number (copy of
  68.         # /proc/version).  It is used to ensure that ferm is re-run
  69.         # after a kernel upgrade.
  70.  
  71.         if ! diff /proc/version $CACHE_FILE.kernel >/dev/null 2>&1 || \
  72.             ! [ -f $CACHE_FILE -a \
  73.             $CACHE_FILE -nt $CONFIG -a \
  74.             -z "`find /etc/ferm -maxdepth 2 -newer $CACHE_FILE 2>/dev/null`" -a \
  75.             $CACHE_FILE -nt /etc/default/ferm -a \
  76.             $CACHE_FILE -nt /etc/init.d/ferm -a \
  77.             $CACHE_FILE -nt $FERM ]; then
  78.             rm -f "$CACHE_FILE" "$CACHE_FILE".tmp "$CACHE_FILE".kernel || return $?
  79.             if [ "$FAST" = "yes" ]; then
  80.                 $FERM $OPTIONS --shell $CONFIG >$CACHE_FILE.tmp || return $?
  81.             else
  82.                 $FERM $OPTIONS --shell --slow $CONFIG >$CACHE_FILE.tmp || return $?
  83.             fi
  84.             cp /proc/version $CACHE_FILE.kernel
  85.             mv $CACHE_FILE.tmp $CACHE_FILE || return $?
  86.         else
  87.             . $CACHE_FILE || return $?
  88.         fi
  89.     else
  90.         if [ "$FAST" = "yes" ]; then
  91.             $FERM $OPTIONS $CONFIG || return $?
  92.         else
  93.             $FERM $OPTIONS --slow $CONFIG || return $?
  94.         fi
  95.     fi
  96. }
  97.  
  98. case "$1" in
  99.     start)
  100.         log_daemon_msg "Starting $DESC" "$NAME"
  101.         if configure_ferm; then
  102.         log_end_msg $?
  103.     else
  104.         log_end_msg $?
  105.  
  106.         if ! test "$VERBOSE" = no -o -f /proc/net/ip_tables_names; then
  107.             log_warning_msg "Looks like the ip_tables module is not loaded, see /etc/modules"
  108.         fi
  109.     fi
  110.         ;;
  111.     stop)
  112.         log_daemon_msg "Stopping $DESC" "$NAME"
  113.         OPTIONS="$OPTIONS --flush"
  114.         configure_ferm stop
  115.         log_end_msg $?
  116.         ;;
  117.     reload|restart|force-reload)
  118.         log_begin_msg "Reloading $DESC configuration..."
  119.         configure_ferm
  120.         log_end_msg $?
  121.         ;;
  122.     *)
  123.         N=/etc/init.d/$NAME
  124.         log_action_msg "Usage: $N {start|stop|restart|reload|force-reload}"
  125.         exit 1
  126.         ;;
  127. esac
  128.  
  129. exit 0
  130.